<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <body>

        <ui:composition template="./../Template.xhtml">


            <ui:define name="content">
                <h:form id="form2">
                    <p:growl id="escola"/>
                    <h:panelGrid columns="2" id="pnlLab">
                        <f:facet name="header">
                            Cadastro de Escolas
                        </f:facet>
                        <h:outputText value="Escola.:"/>
                        <p:inputText value="#{escolaFaces.selectedEscola.escola}" label="Escola" id="Escola" size="80"  maxlength="120" required="true" />
                        <h:outputText value="Município.:"/>
                        <p:inputText value="#{escolaFaces.selectedEscola.municipio}" label="Municipio" id="Municipio" size="60" maxlength="70"  required="true"/>
                        <h:outputText value="INEP.:" />
                        <p:inputText value="#{escolaFaces.selectedEscola.inep}" label="Inep" id="Inep" size="8" maxlength="8" required="true" />

                    </h:panelGrid>
                    <br/>
                    <p:commandButton value="Novo" update="form2:pnlLab" process="@this" actionListener="#{escolaFaces.reset()}"/> 
                     <p:commandButton value="Gravar" action="#{escolaFaces.add()}"  update="escList" id="gravar"/>      
                    <br/>
                    <br/>

                     <p:dataTable var="esc" value="#{escolaFaces.allEscolas}" id="escList" editable="true">
                            <f:facet name="header">
                                Lista de Escolas
                            </f:facet>

                            <p:ajax event="rowEdit" listener="#{escolaFaces.onEdit}" update=":form2:escola" />
                            <p:ajax event="rowEditCancel" listener="#{escolaFaces.onCancel}" update=":form2:escola" />

                            <p:column headerText="Escola" style="width:30%">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{esc.escola}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <h:selectOneMenu value="#{escolaFaces.selectedEscola}" converter="EscolaConverter" >
                                            <f:selectItems value="#{escolaFaces.allEscolas}" 
                                                           var="esc" 
                                                           itemLabel="#{esc.escola}"
                                                           itemValue="#{esc}" />
                                        </h:selectOneMenu>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>

                            <p:column headerText="Município" style="width:20%">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{esc.municipio}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:inputText value="#{esc.municipio}" style="width:100%" label="Município"/>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>

                            <p:column headerText="Inep" style="width:24%">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{esc.inep}" />
                                    </f:facet>
                                    <f:facet name="input">
                                          <p:inputText value="#{esc.inep}" style="width:100%" label="INEP"/>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>

                        

                            <p:column style="width:6%">
                                <f:facet name="header">
                                    Editar
                                </f:facet>
                                <p:commandButton action="#{escolaFaces.editEscola()}" ajax="false" immediate="true" icon="ui-icon-pencil" >
                                    <f:setPropertyActionListener target="#{escolaFaces.selectedEscola}" value="#{esc}"/>
                                </p:commandButton>
                            </p:column>
                            <p:column style="width: 6%">
                                <f:facet name="header">
                                    Apagar
                                </f:facet>
                                <p:commandButton   action="#{escolaFaces.del()}"  ajax="false" update="form2:escList" icon="ui-icon-trash" alt="Apagar Informações" label="Apagar" immediate="true">
                                    <f:setPropertyActionListener target="#{escolaFaces.selectedEscola}" value="#{esc}"/>
                            </p:commandButton>
                            </p:column>
                        </p:dataTable>



                </h:form>          

            </ui:define>



        </ui:composition>

    </body>
</html>
